
function myaxios(config) {
    return new Promise((resolve,reject) => {
        var xhr = new XMLHttpRequest()
        if (config.params){
            const paramsObj = new URLSearchParams(config.params)
            const querypString = paramsObj.toString()
            config.url += '?'+querypString+''
        }
        xhr.open(config.method || 'GET',config.url)
        xhr.addEventListener('loadend',function () {
            if (xhr.status>=200 && xhr.status<300){
                try {
                    resolve(JSON.parse(xhr.response))
                }catch (e){
                    resolve(xhr.response)
                }
            }else {
                reject(new Error(xhr.response))
            }
        })
        if (config.data){
            xhr.setRequestHeader('Content-Type','application/json')
            xhr.send(JSON.stringify(config.data))
        }else {
            xhr.send()
        }
    })
}
